package mylab.commons.web.mvc.controller;

import cn.hutool.core.bean.BeanUtil;
import mylab.base.model.entity.Entity;
import mylab.common.context.UserContext;
import mylab.starters.mybatis.template.SuperService;
import mylab.usm.api.model.account.User;

import java.io.Serializable;

/**
 * 基础controller,核心思想是每个controller服务对应的entity，内置entity对应的service
 *
 * @param <K> 对应的entity的ID
 * @param <E> 对应的entity
 * @param <S> 对应的service
 */
public interface BaseController<K extends Serializable, E extends Entity<K>, S extends SuperService<K, E>> {

    Class<E> getEntityClass();

    S getService();

    default User getSessionUser() {
        return UserContext.getUser();
    }

    default E dtoToPo(Object dto) {
        return BeanUtil.toBean(dto, getEntityClass());
    }

}
